package com.ebeitech.auction.http;

import android.content.Context;

import com.ebeitech.auction.R;
import com.ebeitech.auction.application.EbeiApplication;

/**
 * Created by alice on 2017/11/13.
 */
public class EbeiErrorCode {

	public final static int ERROR_CODE_TOKEN_INVALID = -100;
	public final static int ERROR_CODE_NET_ERROR = -2;
	public final static int ERROR_CODE_NET_UNCONNECT = -3;
	public final static int ERROR_CODE_CODE_FAILED = -4;// 后台返回不成功
	public final static int ERROR_CODE_LOGIN_FAILED = -1;

	private int errorCode;
	private String errorMsg;
	private Object result;

	public EbeiErrorCode() {
	}

	public EbeiErrorCode(int errorCode) {
		this.errorCode = errorCode;
		initErrorMsgWithCode();
	}

	public EbeiErrorCode(int errorCode, String errorMsg) {
		this.errorCode = errorCode;
		this.errorMsg = errorMsg;
	}

	public int getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(int errorCode) {
		this.errorCode = errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}

	public void initErrorMsgWithCode() {
		Context context = EbeiApplication.getContext();
		if (errorCode == ERROR_CODE_NET_UNCONNECT) {
			errorMsg = context.getString(R.string.ebei_network_disconnect);
		} else if (errorCode == ERROR_CODE_NET_ERROR) {
			errorMsg = context.getString(R.string.ebei_network_load_failure);
		} else if (errorCode == ERROR_CODE_LOGIN_FAILED) {
			errorMsg = context.getString(R.string.ebei_login_failure);
		}
	}
}